import React, { Component } from 'react';
import * as api from '../../config/api.js'
import * as tools from '../../config/tools.js'
import { Link, withRouter } from 'react-router-dom';
//待预约预约登记

class Dregister extends Component {
  constructor(args) {
    super();
    this.state = {
      personName: '',
      policyNo: '',
      salesTel: '', //营销员电话
      salesId: localStorage.getItem('salesId'),
    }
  }
  componentDidMount() {
    if (this.props.location.query) {
      this.setState({
        personName: this.props.location.query.personName,
        policyNo: this.props.location.query.policyNo,
      })
    }
  }
  order() {
    if(!this.state.salesTel){
      tools.toast.text('请输入营销员电话')
      return;
    }
    let params = {
      personName: this.state.personName,
      policyNo: this.state.policyNo,
      salesTel: this.state.salesTel //营销员电话
    }
    api.selectPolicyNoStatus(params).then((data) => {
      if (data.flag === '1') {
        this.props.history.push(`/hospitallist/${data.checkUpOrderId}`)
      } else {
        tools.toast.error('预约失败')
      }
    })
  }
  render() {
    return (
      <div>
      <header className="mui-bar mui-bar-nav">
      <h1 className="mui-title">预约</h1>
      </header>
      <div className="mui-content">
      <div className="yuyue">
      <ul>
      <li>
      <input className="yuyue-ico1" type="text" placeholder="保单号" value={this.state.policyNo}
      onChange={(e)=>this.setState({policyNo:e.target.value})}/>
      </li>
      <li>
      <input className="yuyue-ico2" type="text" placeholder="姓名" value={this.state.personName}
      onChange={(e)=>this.setState({personName:e.target.value})} />
      </li>
      <li>
      <input className="yuyue-ico3" type="text" placeholder="营销员电话" value={this.state.salesTel}
      onChange={(e)=>this.setState({salesTel:e.target.value})} />
      </li>
      <li>
      <input  className="yuyue-ico4" type="text" placeholder="营销员代码" value={this.state.salesId}
       onChange={(e)=>this.setState({salesId:e.target.value})} />
      </li>
      </ul>
      <button type="button" className="mui-btn mui-btn-danger mui-btn-block" onClick={()=>{this.order()}}>现在预约</button>
      </div>
      </div>
      </div>
    );
  }
}

export default withRouter(Dregister);